# awm_m11p驱动测试构建文件

if build_tests
    # 创建测试专用的静态库，包含接口源文件和驱动源文件，设置 -fvisibility=default 导出符号
    innosilicon_interface_sources = files(
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/gpu/power.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/gpu/status.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/gpu.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/memory.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/pcie_card.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/pcie_device.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/interface/processor.cpp',
    )
    
    awm_m11p_card_gpu_memory_sources = files(
        '../../../../../drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_card.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_gpu.cpp',
        '../../../../../drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_memory.cpp',
    )
    
    # 测试专用的静态库，覆盖 -fvisibility=hidden，使用 -fvisibility=default 导出符号
    # 注意：需要包含 innosilicon 驱动的所有 include 路径，因为接口源文件使用相对路径引用头文件
    awm_m11p_test_static_lib = static_library(
        'awm_m11p_test',
        innosilicon_interface_sources + awm_m11p_card_gpu_memory_sources,
        include_directories: [
            include_directories('../../../../../drivers/pcie_gpu_card/innosilicon'),
            include_directories('../../../../../drivers/pcie_gpu_card/innosilicon/interface'),
            include_directories('../../../../../include'),
            include_directories('../../../../../gen/include'),
            include_directories('../../../../../drivers/chip'),
            include_directories('../../../../../drivers/internal'),
            include_directories('../../../../../drivers/bus/i2c'),
            include_directories('../../../../../libraries'),
            include_directories('../../../../../libraries/smbus'),
            include_dirs,  # 放在最后，避免其他路径干扰
        ],
        dependencies: [
            dev_deps,
        ],
        cpp_args: ['-fvisibility=default', '-DUNIT_TEST'],
        install: false,
    )

    test_awm_m11p_abi_sources = [
        '../../../../main.cpp',
        'test_awm_m11p_abi.cpp',
        'test_awm_m11p_card.cpp',
        'test_awm_m11p_gpu.cpp',
        'test_awm_m11p_memory.cpp',
    ] + chip_interface_sources + blockio_interface_sources

    test_awm_m11p_abi = executable(
        'test_awm_m11p_abi',
        test_awm_m11p_abi_sources,
        include_directories: [
            include_dirs,
            include_directories('../../../../../drivers/pcie_gpu_card/innosilicon'),
            include_directories('../../../../../drivers'),
            include_directories('../../../../../drivers/bus/i2c'),
            include_directories('../../../../../drivers/internal'),
            include_directories('../../../../../drivers/chip'),
            include_directories('../../../../../libraries/smbus'),
        ],
        dependencies: [
            gtest_dep,
            test_utilities_dep,
            test_utils_dep,
            dev_deps,
        ],
        link_whole: [internal_static_lib, awm_m11p_test_static_lib],
        link_args: ['-ldl'],
        cpp_args: ['-DUNIT_TEST'],
        install: false,
    )

    test('test_awm_m11p_abi', test_awm_m11p_abi,
         workdir: meson.build_root(),
         timeout: 180)
endif
